package com.common;

import com.common.excel.ExcelImportUtils;
import com.common.excel.ExcelModelUtils;
import com.common.excel.entity.UserExcelEntity;

import java.io.File;
import java.util.*;

public class EasyExcelPoiApplication {

    public static void main(String[] args) {
        String fileName = "src/main/resources/userE.xlsx";
        // 根据实体类生成模板
        ExcelModelUtils.exportData(fileName, "用户", UserExcelEntity.class, data());
        // easyExcel读取
        List<Map<Integer, String>> data = ExcelImportUtils.importData(new File("C:\\Users\\ecidi\\Desktop\\user.xlsx"), 0, UserExcelEntity.getRowNum());
        File file = new File("src/main/resources/user.xlsx");
        System.out.println(data);
        // poi读取
        List<Object> list = ExcelImportUtils.importData((s, i) -> {
            Map<String, String> map = new HashMap<>();
            map.put("name", ExcelImportUtils.value(s, i, 0));
            map.put("sex", ExcelImportUtils.value(s, i, 1));
            map.put("age", ExcelImportUtils.value(s, i, 2));
            map.put("date", ExcelImportUtils.value(s, i, 3));
            return map;
        }, file, 4);
        System.out.println(list);
    }

    public static List<UserExcelEntity> data() {
        UserExcelEntity studentTable = new UserExcelEntity();
        List<UserExcelEntity> list = new ArrayList<>();
        studentTable.setUsername("漳卅");
        studentTable.setNickname("aiai");
        studentTable.setPassword("123456");
        studentTable.setEmail("123456@qq.com");
        studentTable.setAvatar("13231");
        studentTable.setStatus("1");
        studentTable.setCreatedTime(new Date());
        list.add(studentTable);
        return list;
    }
}
